# Python 2.6.4
# Project Euler, Problem 98
# Copyright 2010 Talha Zaman

import string
from mine import perms
from math import sqrt

def squares(w1, w2):
    chars = "".join(set(w1)) #unique chars
    if len(chars)>5: return 0
    perm = perms("1234567890", len(chars))
    for p in perm:
        t = string.maketrans(chars, p)
        n1, n2 = w1.translate(t), w2.translate(t)
        if n1[0]=='0' or n2[0]=='0': continue
        n1, n2 = int(n1), int(n2)
        if sqrt(n1)==int(sqrt(n1)) and sqrt(n2)==int(sqrt(n2)):
            return max(n1, n2)
    return 0

words = open("words.txt").readline().strip('"').split('","')
a = dict()
for w in words:
    k = tuple([w.count(chr(i)) for i in range(65,91)])
    if a.has_key(k): a[k].append(w)
    else: a[k] = [w]

m = 0
for k,v in a.iteritems():
    if len(v)>1:
        for i in range(len(v)):
            for j in range(i+1, len(v)):
                if v[i]==v[j][::-1]: continue
                s = squares(v[i], v[j])
                if m<s: m=s
print m
